#include <bits/stdc++.h>

using namespace std;
#define int long long

void solve()
{
    int l , r;
    cin >> l >> r;
    if(l == 1 && r == 1) cout << 1 << endl;
    else cout << r - l << endl;
}
signed main()
{
    int tt; cin >> tt;
    while(tt--)
    {
        solve();
    }
    return 0;
}